package com.cy.gameserver.controller;

import com.cy.gameserver.dao.entity.GPSSign;
import com.cy.gameserver.data.CommonResponse;
import com.cy.gameserver.service.GPSSignService;
import com.cy.gameserver.utils.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by tiankai.qin on 18/4/9.
 */
@Controller
@RequestMapping("/api/gps")
public class GPSCtrl {

    private static final Logger logger = LoggerFactory.getLogger(GPSCtrl.class);


    @Autowired
    private GPSSignService gpsSignService;

    /**
     * 签到留言
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/mark")
    public String receiveGpsSign(GPSSign gpsSign) {
        gpsSignService.saveGPSSign(gpsSign);
        return JsonUtil.toJSON(CommonResponse.commonSucc());
    }


    /**
     * 根据gps的xy坐标以及指南针指向，搜索方圆n米之内的签到留言
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/search")
    public String searchGpsSign(@RequestParam float x, @RequestParam float y, @RequestParam float r) {
        logger.info(String.format("x:%f y:%f r:%f", x, y, r));
        List<GPSSign> gpsSigns = gpsSignService.getGPSSign(x, y, r);
        CommonResponse response = CommonResponse.commonSucc();
        response.setData(gpsSigns);
        return JsonUtil.toJSON(response);
    }

}
